package demo2;

//class MyArray {
//    public Object[] array = new Object[10];
//    public Object getPos(int pos) {
//        return this.array[pos];
//    }
//    public void setVal(int pos,Object val) {
//        this.array[pos] = val;
//    }
//}

import java.lang.reflect.Array;
import java.util.Arrays;

class MyArray<T> {
    public T[] array;//1

    /**
     * 通过反射创建，指定类型的数组
     * @param clazz
     * @param capacity
     */

    public MyArray(Class<T> clazz, int capacity) {
        array = (T[])Array.newInstance(clazz, capacity);
    }
    public T getPos(int pos) {
        return this.array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
    public T[] getArray() {
        return array;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<>(Integer.class, 10);//2
            Integer[] strings = myArray.getArray();
    }
}


